var express = require('express')
var router = express.Router()

const { getALL, getById, exec } = require('../db')

//获取归档文章
router.get('/', async (req, res) => {
  //解析请求参数
  //编写sql语句
  let sql = `select id,title,author,updated_time,date(updated_time) as timestamp from articles order by updated_time desc`
  const data = await getALL(sql)
  //返回数据
  res.send({
    code: 0,
    message: '获取所有归档数据',
    result: {
      data,
    },
  })
})

//获取侧边文章名(时间前五)
router.get('/new', async (req, res) => {
  let sql = `select id,title from articles ORDER BY updated_time desc limit 5`
  const data = await getALL(sql)
  res.send({
    code: 0,
    message: '获取侧边文章',
    result: {
      data,
    },
  })
})

module.exports = router
